package com.srcpoint.common.text
{
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.utils.Dictionary;

	public class TextManager
	{
		private var dic:Dictionary;
		private static var _defaultTextFormat:TextFormat = new TextFormat("SRCPOINT_FONT",14,0xff0000);
		public static var instance:TextManager;
		public static function getInstance():TextManager{
			if(instance==null){
				instance =new TextManager();
			}
			return instance;
		}
		
		public function TextManager()
		{
			dic = new Dictionary();
		}
		public function createDefaultTextField(txt:String,type:String=''):TextField{
			var tf:CTextField = new CTextField();
			var sty:TextStyle = getTextStyle(type)
			tf.defaultTextFormat = sty;
			tf.selectable = sty.selectable;
			tf.text = txt;
			tf.height = tf.textHeight+3;
			tf.width =tf.textWidth+10;
			return tf;
		}
		
		private var styles:Object = {};
		public function initTextStyle(setting:XML):void{
			styles["TF_"] = new TextStyle();
			styles["TF_null"] = styles["TF_"];
			var style:TextStyle;
			for each(var xml:XML in setting.children()){
				style = new TextStyle();
				style.id = xml['@id']
				for each(var attr:XML in xml.children()){
					if(style.hasOwnProperty(attr["@name"])){
						style[attr['@name']]=attr['@value'];
					}	
				}
				styles["TF_"+style.id] = style;
			}
		}
		
		public function getTextStyle(name:String):TextStyle{
			return styles["TF_"+name];
		}
	}
}